<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>管理员页面</title>
    <link rel="stylesheet" href="/static/css/admin.css"/>
    <link rel="stylesheet" href="/static/css/amazeui.min.css">
    <link rel="stylesheet" href="/static/css/app.css">
</head>

<body data-type="generalComponents">
<!--------------------top1------------------>
<header class="am-topbar am-topbar-inverse admin-header">


    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list tpl-header-list">

            <!-------个人中心-------------------->
            {% if admin %}
                <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                    <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                        <span class="tpl-header-list-user-nick">{{ admin.admin_name }}</span><span
                            class="tpl-header-list-user-ico">
                      <img src="{{ admin.admin_face }}">
                    </span>
                    </a>
                    <ul class="am-dropdown-content">
                        <li>
                            <a href="#"><span class="am-icon-bell-o"></span> 资料</a>
                        </li>
                        <li>
                            <a href="#"><span class="am-icon-cog"></span> 设置</a>
                        </li>
                        <li>
                            <a href="/admin/adminLogout"><span class="am-icon-power-off"></span> 退出</a>
                        </li>
                    </ul>
                </li>
            {% endif %}
            {% if not admin %}
                <li class="am-dropdown">
                    <a href="/admin/adminLogin"><p style="color: #0a628f">登录</p></a>
                </li>
            {% endif %}
            <!-------个人中心------------------------------------------>

            <li style="margin-right: 40px;"></li>
        </ul>
    </div>
</header>
<!---------------header-------------------------->
<!---    左侧导航栏---------------->
<div class="tpl-page-container tpl-page-header-fixed">

    <div class="tpl-left-nav tpl-left-nav-hover">


        <div class="tpl-left-nav-list">
            <ul class="tpl-left-nav-menu">
                <li class="tpl-left-nav-item">
                    <a href="#" class="nav-link">
                        <i class="am-icon-home"></i>
                        <span>首页</span>
                    </a>
                </li>
                <li class="tpl-left-nav-item">
                    <a href="/admin/addFindGoodItem/" class="nav-link tpl-left-nav-link-list">
                        <i class="am-icon-bar-chart"></i>
                        <span>失物招领</span>
                        <span id="msgCount"></span>

                    </a>
                </li>
                <li class="tpl-left-nav-item">
                    <a href="/school/schoolNewsList/" class="nav-link tpl-left-nav-link-list">
                        <i class="am-icon-bar-chart"></i>
                        <span>校园新闻</span>
                        <span id="msgCount"></span>
                    </a>
                </li>

                <li class="tpl-left-nav-item">
                    <a href="javascript:;" class="nav-link tpl-left-nav-link-list active">
                        <i class="am-icon-wpforms"></i>
                        <span>查看所有用户</span>
                    </a>
                </li>

                <li class="tpl-left-nav-item">
                    <a href="/admin/adminLogin" class="nav-link tpl-left-nav-link-list">
                        <i class="am-icon-key"></i>
                        <span>登录</span>

                    </a>
                </li>

            </ul>
        </div>
    </div>
    <!---    左侧导航栏---------------->

    <div class="tpl-content-wrapper">
        <div class="tpl-portlet-components">
            <div class="portlet-title">
                <div class="caption font-green bold">
                    <span class="am-icon-code"></span> 列表
                </div>

            </div>
            <div class="tpl-block">
                <div class="am-g">
                    <div class="am-u-sm-12">
                        <form class="am-form">
                            <table class="am-table am-table-striped am-table-hover table-main">
                                <thead>
                                <tr>
                                    <th class="table-title">用户名</th>
                                    <th class="table-type">用户信誉度</th>
                                    <th class="table-type">交易次数</th>
{#                                    <th class="table-author am-hide-sm-only">投诉次数</th>#}
                                    <th class="table-date am-hide-sm-only">注册日期</th>
                                    <th class="table-set" style="margin-left: 500px;">操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                {% if users %}
                                    {% for user in users %}
                                        <tr>
                                            <td>{{ user.username }}</td>
                                            <td>{{ user.credit }}%</td>
                                            <td class="am-hide-sm-only">{{ user.trans_count }}</td>
                                            <td class="am-hide-sm-only">{{ user.reg_time }}</td>
                                            <td>
                                                <div class="am-btn-toolbar">
                                                    <div class="am-btn-group am-btn-group-xs">
                                                        <a href="/admin/deleteUser/{{ user.user_id }}">
                                                            <div class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                                <span class="am-icon-trash-o"></span>删除用户
                                                            </div>
                                                        </a>
                                                        {% if user.alert_time<3 %}
                                                            <a onclick="alertUser('{{ user.user_id }}')">
                                                                <div class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                                     警告用户
                                                                </div>
                                                            </a>
                                                        {% endif %}
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                {% endif %}

                                </tbody>
                            </table>
                            <hr>

                        </form>
                    </div>

                </div>
            </div>
            <div class="tpl-alert"></div>
        </div>

    </div>

</div>

<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/js/amazeui.min.js"></script>
<script src="/static/js/app.js"></script>
<script type="text/javascript">
    $(function () {
        $.ajax({
            url: "/admin/checkCount/",
            cache: "false",
            async: "true",
            dataType: "json",
            type: "get",
            success: function (data) {
                var count = data.check_count;
                var admin_name ={{admin.admin_name }};
                if (count != 0 && admin_name != '') {
                    $(msgCount).append("<i class='tpl-left-nav-content tpl-badge-danger'>" + count + "</i>")
                }
            },
            error: function () {
                alert("服务器端异常");
            }
        });
    })
</script>

<script>
    function alertUser(user_id) {
        var data = {"user_id": user_id};
        console.log(user_id);
        $.ajax({
            type: "get",
            data: data,
            url: '/admin/alertUser',
            dataType: 'json',
            success: function (result) {
                if(result.Code==200)
                {
                    alert("已发送警告！");
                    emailNotify();
                    location.href="/admin/manageUser/"
                }
            },
            error: function (result) {
                alert("系统异常！")
            }
        });
    }

    function emailNotify() {
        $.ajax({
            type: "get",
            url: '/admin/sendMail',
            dataType: 'json',
            success: function (result) {

            },
            error: function (result) {
            }
        });
    }
</script>
</body>

</html>